app.controller('RtTaskResModalCtrl', function ($scope, $modalInstance, toaster, param, ajax) {

	$scope.submitting = false;
	$scope.timeRange = {};
	$scope.param = param;
	if ($scope.param.data == null) {
		$scope.param.data = {};
	}
	$scope.reslist = [];

	//车辆资源
	$scope.loadRes = function () {
		ajax.call(new Req.GET({
			resource: 'res/rt/' + $scope.param.data.shift.route.id + '/' + $scope.param.data.total + '/list'
		})).then(function (result) {
			$scope.list = result.result;
			if (result.code != 404) {
				$scope.reslist = $scope.list;
			} else {
				$scope.ts = " 此线路暂时没有空闲资源可以使用！请在约租票池里进入对应线路的资源列表，设置或添加可用资源。";
			}
		}, function () { });
	};
	$scope.loadRes();

	//任务状态
	$scope.loadStatusList = function () {
		$scope.statusList =
			[
				{ id: 1, name: "已创建" },
				{ id: 2, name: "已分配" },
				{ id: 3, name: "进行中" },
				{ id: 4, name: "已完成" },
				{ id: 5, name: "已取消" },
				//             { id: 6, name: "已失败" },
				//             { id: 7, name: "已中止" },
				//             { id: 8, name: "未执行" },

			];
		if ($scope.param.data.status != 0) {
			$scope.statusList.selected = $scope.statusList[$scope.param.data.status - 1];
		}
	};
	$scope.loadStatusList();

	$scope.ok = function () {
		if ($scope.myForm.$valid) {
			if ($scope.reslist.selected) {
				$scope.param.data.resource = $scope.reslist.selected;
			} else {
				toaster.pop('warning', '提示', '请选择车辆资源！');
				return;
			}
			$modalInstance.close($scope.param);
		}
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
		$scope.submitting = false;
	};
});
